package com.hm.system.service.elasticsearch;

import java.util.Iterator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hm.system.elasticsearch.domain.EsSysUserInfo;
import com.hm.system.mongo.vo.system.SysUserInfoVo;
import com.hm.system.share.repository.elasticsearch.system.EsSysUserInfoRepository;
import com.hm.system.share.service.elasticsearch.system.EsSysUserInfoService;
import com.hm.system.share.service.mongo.system.SysUserInfoService;

/**
 * @author shishun.wang
 * @date 下午4:55:04 2016年6月6日
 * @version 1.0
 * @describe 
 */
@Service
public class EsSysUserInfoServiceImpl implements EsSysUserInfoService {

	@Autowired
	private EsSysUserInfoRepository esSysUserInfoRepository;
	
	@Autowired
	private SysUserInfoService sysUserInfoService;
	
	@Override
	public void saveEsSysUserInfo(String userId) {
		SysUserInfoVo sysUserInfoVo = sysUserInfoService.getSysUserInfo(userId);
		
		EsSysUserInfo esSysUserInfo = new EsSysUserInfo();
		{
			esSysUserInfo.setId(sysUserInfoVo.getId());
			esSysUserInfo.setName(sysUserInfoVo.getName());
			esSysUserInfo.setAlias(sysUserInfoVo.getAlias());
			esSysUserInfo.setMobile(sysUserInfoVo.getMobile());
		}

		esSysUserInfoRepository.save(esSysUserInfo);
	}

	@Override
	public void queryTest() {
		Iterator<EsSysUserInfo> iterator = esSysUserInfoRepository.findAll().iterator();
		while(iterator.hasNext()){
			System.out.println(iterator.next());
		}
	}

}
